import axios from 'axios'
import api from "./server-api";

var _url = api.ip
// var _url = 'http://47.107.159.133:80'

const listApi = (callback) => {
  const url = _url + '/advertising/'
  axios.get(url).then(num => {
    console.log(num.data);
    callback && callback(num.data)
  })
}

const advertisingPost = (goodsId,imageId,callback) => {
  const url = _url + '/advertising/?goodsId='+ goodsId +'&imgId=' + imageId;
  axios.post(url).then(num => {
    console.log(num.data);
    callback && callback(num.data)
  })
}

//根据id删除
const DelApi = (id,callback) => {
  const url = _url + '/advertising/?advId='+id
  axios.delete(url).then(num => {
    callback && callback(num.data)
  })
}

//未完成
// 连后台接口部分
// 上传 UploadFiles
export function UploadFiles(formData) {
  return request({
    url: '/advertising/',
    method: 'post',
    data: formData + '?goodsId=1'
  })
}


export {
  listApi, // 自动刷新
  advertisingPost,  //添加
  DelApi,   //删除
}
